package controller.impl;

import controller.Controller;
import controller.FunctionController;

import javax.swing.*;

import model.container.ResourceDispatcher;

/**
 * Created by IntelliJ IDEA.
 * User: QIUKX of Freshpower.com.cn
 * Date: 2008-2-25
 * Time: 16:23:02
 */
public class FunctionControllerImpl implements FunctionController {
    private JPanel lastPanel;
    private JPanel currentPanel;
    private ResourceDispatcher dispatcher;

    public ResourceDispatcher getDispatcher() {
        return dispatcher;
    }

    public void setDispatcher(ResourceDispatcher dispatcher)  throws Exception{
        this.dispatcher = dispatcher;
    }

    public int forward(JFrame parent, String panelName) throws Exception {
        JPanel panel = dispatcher.getPanel(panelName);
        lastPanel = currentPanel;
        currentPanel = panel;

        parent.setContentPane(panel);
        return 0;
    }

    public int backward(JFrame parent, String panelName) throws Exception {
        JPanel temp = currentPanel;
        currentPanel = lastPanel;
        lastPanel = temp;

        parent.setContentPane(currentPanel);
        return 0;
    }

    private int update(JFrame frame){
        SwingUtilities.updateComponentTreeUI(frame);
        return 0;
    }
}
